package vertx;

import io.vertx.core.Vertx;
import io.vertx.core.WorkerExecutor;
import netty.util.StartAndStop;
import test.PerformanceAnalyze;

import java.util.concurrent.TimeUnit;

public class Executor extends StartAndStop {

    PerformanceAnalyze performanceAnalyze = new PerformanceAnalyze();

    WorkerExecutor workerExecutor = Vertx.vertx().createSharedWorkerExecutor("Executor-1", 1000, 1, TimeUnit.SECONDS);

    public void start() {
        while (running) {
            long start = System.nanoTime();
            workerExecutor.executeBlocking(handler -> {
                performanceAnalyze.meter();
                performanceAnalyze.delay(System.nanoTime() - start);
            }, false);
        }
    }

    public static void main(String[] args) {
        new Executor().start();

    }

}
